import { defineStore } from 'pinia'
import { userActionAPI } from '@/api/common'
import { getFactoryAPI } from '@/api/shop'

export const useSendMsgStore = defineStore('SendMsgStore', {
    state() {
        return {
            sendMsgCount: 0
        }
    },
    actions: {
        async addView(bindId: string) {
            this.sendMsgCount++
            console.log(bindId, '浏览量', this.sendMsgCount)
            if (this.sendMsgCount !== 1) return
            console.log(bindId, '浏览量====', this.sendMsgCount)
            const arr = bindId.split('-')
            let id = arr[arr.length - 1]
            // let id = '4397'

            if (arr[0].includes('factory')) {
                const res = await getFactoryAPI(id, { type: 2 })
                id = res.data.id
            }

            // 获取工厂消息
            // 添加浏览量请求
            userActionAPI({
                type: 6,
                bindId: id,
                action: arr[0].includes('factory') ? 60 : 61 //60.咨询店铺 61.咨询用户
            })
        }
    }
})
